package com.javasm.crm.controller.b2cReturns;


import com.javasm.crm.common.http.AxiosResult;
import com.javasm.crm.controller.base.BaseController;
import com.javasm.crm.domin.criteria.B2cReturnsApplyCriteria;
import com.javasm.crm.domin.entity.b2cReturns.B2creturnsapply;
import com.javasm.crm.domin.vo.B2creturnsapplyVO;
import com.javasm.crm.service.b2cReturns.B2cReturnsApplyService;
import com.javasm.crm.utils.page.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  退换货申请
 * </p>
 *
 * @author wxl
 * @since 2021-07-12
 */
@RestController
@Api(value = "b2cReturnsApplyController", description = "退换货申请单管理")
@RequestMapping("b2cReturnsApply")
public class B2cReturnsApplyController extends BaseController {

    @Autowired
    private B2cReturnsApplyService applyService;

    @GetMapping("searchPageByCriteria")
    @ApiOperation(value = "查询退换货申请单", notes = "条件分页查询退换货申请单")
    public AxiosResult<PageResult<B2creturnsapply>> searchPageByCriteria(B2cReturnsApplyCriteria applyCriteria){
        PageResult<B2creturnsapply> b2creturnsapplyPageResult = applyService.searchPageByCriteria(applyCriteria);

        return AxiosResult.success(b2creturnsapplyPageResult);
    }

    @GetMapping("searchDetailByApplyId")
    @ApiOperation(value = "查看退换货申请单详情", notes = "退换货申请单详情")
    public AxiosResult<B2creturnsapplyVO> searchPageByCriteria(String applyId){
        B2creturnsapplyVO b2creturnsapplyVO = applyService.searchDetailByApplyId(applyId);
        return AxiosResult.success(b2creturnsapplyVO);
    }

    @ApiOperation(value = "插入申请单", notes = "添加申请单")
    @PostMapping("saveApply")
    public AxiosResult<Integer> saveApply( @RequestBody B2creturnsapplyVO b2creturnsapplyVO){
        Integer integer = applyService.saveApply(b2creturnsapplyVO);
        return toAxiosResult(integer);
    }

    @ApiOperation(value = "删除申请单", notes = "删除申请单")
    @PostMapping("deleteApply")
    public  AxiosResult<Integer> update(@RequestBody B2creturnsapply b2creturnsapply){
        int delete = applyService.deleteApply(b2creturnsapply);
        return toAxiosResult(delete);
    }

    @ApiOperation(value = "修改申请单", notes = "修改申请单")
    @PostMapping("updateApply")
    public AxiosResult<Integer> updateApply( @RequestBody B2creturnsapplyVO b2creturnsapplyVO){
        Integer integer = applyService.updateApply(b2creturnsapplyVO);
        return toAxiosResult(integer);
    }

    @ApiOperation(value = "审批申请单", notes = "审批申请单")
    @PostMapping("approvalApply")
    public AxiosResult<Integer> approvalApply( @RequestBody B2creturnsapply b2creturnsapply){
        Integer integer = applyService.approvalApply(b2creturnsapply);
        return toAxiosResult(integer);
    }

    @ApiOperation(value = "删除申请单", notes = "删除申请单")
    @DeleteMapping("deleteApplyByApplyIdList")
    public  AxiosResult<Integer> deleteApplyByApplyIdList(@RequestBody List<Serializable> idList){
        int delete = applyService.deleteApplys(idList);
        return toAxiosResult(delete);
    }

    @ApiOperation(value = "生成入库订单", notes = "入库订单")
    @PostMapping("applyToInorder")
    public AxiosResult<Integer> applyToInorder( @RequestBody List<B2creturnsapply> applyIdList){
        Integer integer = applyService.applyToInorder(applyIdList);
        return toAxiosResult(integer);
    }

}
